import axios, { AxiosInstance } from 'axios'
import Nprogress from 'nprogress'
// 1,2,3 -> 6

const instance: AxiosInstance = axios.create({
  timeout: 5000, // 设置过期时间
})

instance.interceptors.request.use(
  (config) => {
    // 开启显示loading...
    Nprogress.start()
    return config
  },
  (err) => {
    return Promise.reject(err)
  }
)

instance.interceptors.response.use(
  (response) => {
    Nprogress.done()
    // console.log('response:', response)
    return response.data
  },
  (err) => {
    return Promise.reject(err)
  }
)

export default instance
